package com.exartisan.adapter;

import java.util.ArrayList;

import com.exartisan.bean.GalleryContent;
import com.exartisan.thanhdoanhn.R;
import com.loopj.android.image.SmartImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class GalleryAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<GalleryContent> content;
	private boolean isPhotoGallery;
	
	
	public GalleryAdapter(Context context, ArrayList<GalleryContent> content, boolean isPhotoGallery) {
		this.context = context;
		this.content = content;
		this.isPhotoGallery = isPhotoGallery;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return content.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	 
			View gridView;
	 
			if (convertView == null) {
	 
				gridView = new View(context);
	 
				// get layout from mobile.xml
				if(isPhotoGallery)
				gridView = inflater.inflate(R.layout.photo_gallery_row, null);  
				else gridView = inflater.inflate(R.layout.video_gallery_row, null);  
				
				// declare
				SmartImageView imageView = (SmartImageView) gridView.findViewById(R.id.imgThumb);
	 
				//fill data
				imageView.setImageUrl(content.get(position).getResourceUrl());
	 
			} else {
				gridView = (View) convertView;
			}
			SmartImageView imageView = (SmartImageView) gridView.findViewById(R.id.imgThumb);
			 
			//fill data
			imageView.setImageUrl(content.get(position).getResourceUrl());
	 
			return gridView;
	}

	public GalleryContent getGalleryContent(int position){
		return content.get(position);
	}
}